<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script>
        //依赖H5
        function testSse() {
            let sse = new EventSource("demo");
            sse.onmessage = function (e) {
                console.log(e.data)
            }
            //添加事件监听 事件名称，回调函数
            sse.addEventListener("e", function (e) {
                console.log("e", e.data)
                if(e.data === 'data-4'){
                    sse.close() //关闭一下，不然会循环
                }
            })
        }
    </script>
</head>
<body>
   <button onclick="testSse()">test-sse</button>
</body>
</html>